package test3;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(8888);

        DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);
        ds.receive(dp);
        byte[] data = dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data, 0, length));

        String message = "接收端的反馈...";
        byte[] bytes = message.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 9099;
        DatagramPacket dp2 = new DatagramPacket(bytes, bytes.length, address, port);
        ds.send(dp2);

        ds.close();
    }
}
